package com.redoor.app.stake.basicdata.controller;

import com.redoor.app.stake.basicdata.model.SyncOperator;
import com.redoor.app.stake.basicdata.service.SyncOperatorService;
import com.redoornetwork.framework.core.response.ResponseResult;
import com.redoornetwork.framework.core.response.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* Created by wangjunlei on 2018-03-15 14:49:11.
*/
@RestController
@RequestMapping("/sync/operators")
public class SyncOperatorController {

    @Autowired
    private SyncOperatorService syncOperatorService;

    @PostMapping
    public ResponseResult add(@RequestBody SyncOperator syncOperator) {
        syncOperatorService.save(syncOperator);
        return ResultGenerator.generatorSuccess();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable String id) {
        syncOperatorService.deleteById(id);
        return ResultGenerator.generatorSuccess();
    }

    @PutMapping
    public ResponseResult update(@RequestBody SyncOperator syncOperator) {
        syncOperatorService.updateBySelective(syncOperator);
        return ResultGenerator.generatorSuccess();
    }

    @GetMapping("/{id}")
    public ResponseResult detail(@PathVariable String id) {
        SyncOperator syncOperator = syncOperatorService.findById(id);
        return ResultGenerator.generatorSuccess(syncOperator);
    }

    @GetMapping("/list")
    public ResponseResult list() {
        List<SyncOperator> list = syncOperatorService.findAll();
        return ResultGenerator.generatorSuccess(list);
    }

}
